<?php

uiLoadLibrary('editor');

class modClassMgr extends cDycmsClientModule
{
	function __construct()
	{
        $this->AddChild($mgr = new cUiManager('$modClassMgr',
        array('Name', 'Description')));

		$mgr->AddChild(uiGetIcon('error').<<<END
<em>Warning:</em> these are advanced settings, which should only be
edited by someone who knows what they are doing. If you have any
doubts, turn back now.
END
			);

        switch($mgr->GetAction()) {
            case 'create':
			
            break;
			
			case 'del':
			
            break;

            case 'edit':
			
			//
			// Editor form for class metadata
			//
			
			$mgr->CreateBlank();
			$cls =& dyLoadClass($mgr->GetObjectId());
			
			dyRequirePriv($cls->GetSpecialPriv());
			
			
			$mgr->AddChild(new cUiTextBox(array(
				'name' => '$modClassMgr-name',
				'value' => $cls->GetName()
			), 'Display Name'));
			$mgr->AddChild(new cUiTextBox(array(
				'name' => '$modClassMgr-description',
				'value' => $cls->GetDescription()
			), 'Description'));
			
			$mgr->AddChild('<b>Token Formats</b>: Special-Write-Read-List(object) DelCls-Manage-Publish-Create(class)');
			
			$mgr->AddChild(new cUiTextBox(array(
				'name' => '$modClassMgr-name',
				'value' => dechex($cls->GetPublicToken())
			), 'Default Public Token'));
			$mgr->AddChild(new cUiTextBox(array(
				'name' => '$modClassMgr-name',
				'value' => dechex($cls->GetProtectedToken())
			), 'Default Protected Token'));
			$mgr->AddChild(new cUiTextBox(array(
				'name' => '$modClassMgr-name',
				'value' => dechex($cls->GetPrivateToken())
			), 'Default Private Token'));
			
			$mgr->AddChild(new cUiTextBox(array(
				'name' => '$modClassMgr-name',
				'value' => dechex($cls->GetToken())
			), 'Class Token'));
			
			$mgr->AddChild(new cUiButtonSet(array(
				'name' => '$modClassMgr-action'
			), array(
				'save-'.$cls->GetClassNum() => uiGetIcon('cog_go').'Save')));
			
            break;

            case 'view':
            header('Location: '.dyViewerUrl($mgr->GetObjectId()));
            break;
	

            default:

            parent::__construct(uiGetIcon('cog')
                .'Class Manager');

            //
			// Fill in the manager form with all classes
			//
			
            $zz = dbReadAllClasses();

            $mgr->CreateForm(dbCountClasses());

            foreach($zz as $zCls){
                $mgr->AddRow($zCls['cnum'], array(
                    $zCls['name'],
                    $zCls['description']
                ), array(
                    new cUiButton(array(
                        'name' => '$modClassMgr-action',
        				'value' => 'view-'.$zCls['id'],
                        'title'=>'View'
        			),'', 'magnifier')
                ));
            }
        } // switch
	}
}

class modSettings extends cDycmsClientModule
{
	function __construct()
	{
        $this->AddChild(uiGetIcon('error')
        	.'Settings module not implemented');
	}
}

class modPackages extends cDycmsClientModule
{
	function __construct()
	{
        $this->AddChild(uiGetIcon('error')
        	.'Packages not implemented');
	}
}

class modIndexMgr extends cDycmsClientModule
{
	function __construct()
	{
        $this->AddChild(uiGetIcon('error')
        	.'Index manager module not implemented');
	}
}
